﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;

namespace NJL.WebManage.Handle
{
    /// <summary>
    /// Handler 的摘要说明
    /// </summary>
    public class Handler : IHttpHandler
    {

        DataSet ds;
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (!string.IsNullOrEmpty(context.Request.QueryString["CompanyId"]))
            {
                string startTime = context.Request.QueryString["startTime"];
                string endTime = context.Request.QueryString["endTime"];
                NJL.BLL.NJL_BOOK_ORDER bllBookOrder = new BLL.NJL_BOOK_ORDER();
                ds = bllBookOrder.GetBookCount("a.VISIT_DATE between '" + startTime + "' and '" + endTime + "' and c.ID='" + context.Request.QueryString["CompanyId"] + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    StringBuilder str = new StringBuilder();
                    str.Append("<table class=\"tableliststyle\" cellspacing=\"0\" rules=\"all\" border=\"1\">");
                    str.Append("<tr class=\"gridheader\">");
                    str.Append("<th style=\"width: 40px;\">序号</th>");
                    str.Append("<th>订票类型</th>");
                    str.Append("<th>订单数量</th>");
                    str.Append("<th>订票数量</th>");
                    str.Append("<th>总金额</th>");
                    str.Append("</tr>");
                    int i = 0;
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        i++;
                        str.Append("<tr>");
                        str.Append("<td align='center'>" + i + "</td>");
                        str.Append("<td align='left'>" + row["BOOK_NAME"].ToString() + "</td>");
                        str.Append("<td align='right'>" + row["订单数量"].ToString() + "</td>");
                        str.Append("<td align='right'>" + row["订票数量"].ToString() + "</td>");
                        str.Append("<td align='right'>" + string.Format("{0:c}", row["总金额"]) + "</td>");
                        str.Append("</tr>");
                    }

                    str.Append("<tr>");
                    str.Append("<td colspan=\"2\" align='left'>合计:</td>");
                    str.Append("<td align='right'>" + ds.Tables[0].Compute("Sum(订单数量)", "true") + "</td>");
                    str.Append("<td align='right'>" + ds.Tables[0].Compute("Sum(订票数量)", "true") + "</td>");
                    str.Append("<td align='right'>" + string.Format("{0:c}", ds.Tables[0].Compute("Sum(总金额)", "true")) + "</td>");
                    str.Append("</tr>");
                    str.Append("</table>");
                    context.Response.Write(str.ToString());
                }

            }
            else if (!string.IsNullOrEmpty(context.Request["componyRemark"]))
            {
                string id = context.Request["componyRemark"];
                string content = context.Request["content"];
                NJL.BLL.NJL_COMPANY bll = new BLL.NJL_COMPANY();
                NJL.Model.NJL_COMPANY model = bll.GetModel(id);
               
            }

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}